using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Text;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Collections;
using System.Drawing.Design;
using System.Web.UI.Design;
using System.ComponentModel.Design;
using System.Globalization;
using System.Reflection;
using System.Security.Permissions;

[assembly: WebResource("CodeStory.WebControls.Resource.HeadLink.js", "application/x-javascript")]

namespace CodeStory.WebControls
{
	[ToolboxData("<{0}:HeaderLink runat=server></{0}:HeaderLink>")]
	[ParseChildren(true)]
	[PersistChildren(false)]
	[AspNetHostingPermission(SecurityAction.LinkDemand, Level = AspNetHostingPermissionLevel.Minimal)]
	public class HeaderLink : WebControl
	{
		LinkItemCollection linkItems;

		[DesignerSerializationVisibility(DesignerSerializationVisibility.Content)]
		[PersistenceMode(PersistenceMode.InnerProperty)]
		[NotifyParentProperty(true)]
		public LinkItemCollection LinkItems {
			get {
				if (linkItems == null)
					linkItems = new LinkItemCollection();
				return linkItems;
			}
		}


		protected override void OnPreRender(EventArgs e) {
			Page.ClientScript.RegisterClientScriptResource(typeof(DataSourceHelper),"CodeStory.WebControls.Resource.CodeStory.js");
			Page.ClientScript.RegisterClientScriptResource(GetType(), "CodeStory.WebControls.Resource.HeadLink.js");
			Page.ClientScript.RegisterStartupScript(GetType(), "HLStart", "CodeStoryHeadLink.Load();",true);
			base.OnPreRender(e);
		}

		protected override void Render(HtmlTextWriter writer) {
			//base.Render(writer);
			StringBuilder sb = new StringBuilder();
			foreach (BaseLinkItem i in LinkItems) {
				sb.Append(i.ToHtmlString(this));
				sb.Append(Environment.NewLine);
			}
			writer.RenderBeginTag(HtmlTextWriterTag.Script);
			writer.Write(sb.ToString());
			writer.RenderEndTag();
		}
	}
}
